import request from '@/utils/request'
import type { PageDto, PageReqDto, PagesDto } from '../types'
import type { CommunicationConfigDto, AddCommunicationConfigReqDto, ConfigListDto, EmailConfigListDto, EditCommunicationConfigReqDto } from './types'


/**
 * 获取推送规则列表
 * @param params 
 * @returns 
 */
export function getEmailConfigList(params: PageReqDto): Promise<PageDto<ConfigListDto>> {
    return request.get('/crm-prod-v2/web/pc/crm/emailConfig/queryPageList', {
        params
    })
}

/**
 * 添加推送规则
 * @param data 
 * @returns 
 */
export function saveCommunicationConfig(data: AddCommunicationConfigReqDto): Promise<void> {
    return request.post('/crm-prod-v2/web/pc/crm/emailConfig/saveCommunicationConfig', data)
}

/**
 * 更新推送规则
 * @param data 
 * @returns 
 */
export function updateCommunicationConfig(data: EditCommunicationConfigReqDto): Promise<void> {
    return request.post('/crm-prod-v2/web/pc/crm/emailConfig/updateCommunicationConfig', data)
}

/**
 * 推送规则详情
 * @param params 
 * @returns 
 */
export function queryConfigDetail(params: {
    id: number
}): Promise<CommunicationConfigDto> {
    return request.get('/crm-prod-v2/web/pc/crm/emailConfig/queryConfigById', {
        params
    })
}

/**
 * 获取推送规则列表
 * @param data 
 * @returns 
 */
export function queryEmailRuleList(params: {
    name?: string
}): Promise<{
    id: number
    ruleName: string
}[]> {
    return request.get('/crm-prod-v2/web/pc/crm/emailConfig/queryNameList', {
        params
    })
}


/**
 * 删除推送规则
 * @param data 
 * @returns 
 */
export function deleteConfig(data: {
    id: number
}): Promise<void> {
    return request.post('/crm-prod-v2/web/pc/crm/emailConfig/deleteConfig', data)
}